package com.lolongmaps.main;
 
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.lolongmaps.model.ParsedData;
 
 
public class WeatherHandler extends DefaultHandler {
       
    private boolean in_forecast_information = false;
    private boolean in_current_conditions = false;
    private boolean in_forecast_conditions = false;
    private ParsedData myParsedData = new ParsedData();   
 
        @Override
        public void startDocument() throws SAXException {
        	
                this.myParsedData = new ParsedData();
        }
 
        @Override
        public void endDocument() throws SAXException {
                // Nothing to do
        }
        
        public ParsedData getParsedData() {
        	
            return this.myParsedData;
        }
 
        @Override
        public void startElement(String namespaceURI, String localName,
                        String qName, Attributes atts) throws SAXException {
        	
        	  if (localName.equals("forecast_information")) {
        		  this.in_forecast_information = true;
        		  
        	  } else if (localName.equals("current_conditions")) {
                  this.in_current_conditions = true;
                  
        	  } else if (localName.equals("forecast_conditions")) {
                  this.in_forecast_conditions = true;
                  
        	  } else {
                  //String dataAttribute = atts.getValue("data");
                  // 'Inner' Tags of "<forecast_information>"
                  if (localName.equals("city")) {
                	  //Do nothing
                  } else if (localName.equals("postal_code")) {
                	  //Do nothing
                  } else if (localName.equals("latitude_e6")) {
                      //Do nothing
                  } else if (localName.equals("longitude_e6")) {
                      //Do nothing
                  } else if (localName.equals("forecast_date")) {
                	  //Do nothing ulet ZZZZZ
                  } else if (localName.equals("current_date_time")) {
                	  //Do nothing
                  } else if (localName.equals("unit_system")) {
                	  //Do nothing
                
                	  /*----------------INNER TAGS NA SUNOD------------------*/
                	  // SHARED(!) 'Inner' Tags within "<current_conditions>" AND
                	  // "<forecast_conditions>"
                  } else if (localName.equals("day_of_week")) {
                      if (this.in_current_conditions) {
                    	  //Do nothing
                      } else if (this.in_forecast_conditions) {
                    	  //Do nothing
                      }
                  } else if (localName.equals("icon")) {
                      if (this.in_current_conditions) {
                          //Do nothing
                      } else if (this.in_forecast_conditions) {
                    	  //Do nothing
                      }
                      
                  } else if (localName.equals("condition")) {
                	  //ETO LANG:
                	  //Dito ko na kinukuha yung string na condition such as cloudy, etc.
                      if (this.in_current_conditions) {
                    	  String attrValue = atts.getValue("data");
                          myParsedData.setParsedForecast(attrValue);
                      } else if (this.in_forecast_conditions) {
                          //Nothing to do here
                      }
                      
                  /*----- 'Inner' Tags within "<current_conditions>"*/    
                  } else if (localName.equals("temp_f")) {
                          //Di na ulet kelangan
                  } else if (localName.equals("temp_c")) {
                          //Don't need baby
                  } else if (localName.equals("humidity")) {
                          //Woops
                  } else if (localName.equals("wind_condition")) {
                          //Woops

                  /*---- 'Inner' Tags within "<forecast_conditions>"*/
                  } else if (localName.equals("low")) {
                          //Nothing to do
                  } else if (localName.equals("high")) {
                          //Nothing to do
                  }
              }
        }
       
        /** Gets be called on closing tags like:
         * </tag> */
        @Override
        public void endElement(String namespaceURI, String localName, String qName)
                        throws SAXException {
        	
            if (localName.equals("forecast_information")) {
                this.in_forecast_information = false;
            } else if (localName.equals("current_conditions")) {
                this.in_current_conditions = false;
            } else if (localName.equals("forecast_conditions")) {
                this.in_forecast_conditions = false;
            }
        }
        
        //For implementation lang
        @Override
        public void characters(char ch[], int start, int length) {
                /*
                 * Would be called on the following structure: <element>characters</element>
                 */
        }
 }